﻿@model Wheeler.Web.ViewModels.TestResultViewModel
@using Wheeler.Web.Utility;
@using Wheeler.Common.Extensions;

@{
    String pageTitle = "Data Sheet";
    //if (Model != null && Model.ID == 0)
    if (Model != null)
    {
        pageTitle = (Model.Vehicle != null && Model.ID > 0) ? String.Format("Edit Data Sheet for {0}", Model.Vehicle.RegistrationNo) : String.Format("Add Data Sheet for {0}", Model.Vehicle.RegistrationNo);
    }
    ViewBag.Title = Html.GetPageTitle(pageTitle);
    if (UserInfo.IsAdmin){
        ViewData[AppConstants.ViewDataKeys.SELECTED_MENU] = AdminMenu.EditTestResult;
    }
    else {
        ViewData[AppConstants.ViewDataKeys.SELECTED_MENU] = OperatorMenu.TestResults;
    }
    bool _HasSaved = ViewData.HasSaved();
}

<div class="jb-page-heading">
    <h1>@pageTitle</h1>
    <div>Enter necessary information and then click the Save button.</div>
</div>
<div class="jb-page-content">
@using (Html.BeginForm())
{
    @Html.ValidationSummary(false)

    if (Model == null)
    {
        @: @Html.WarningMessageBox("Sorry! Requested Test Result was not found for edit.", "Not Found!")
    }
    else if (Model.Vehicle == null)
    {
        @: @Html.WarningMessageBox("Sorry! Requested Auto Rickshaw was not found.", "Not Found!")
    }
    else if (!UserInfo.CanEditTestResult(Model.HasConfirmed, Model.HasPublished))
    {
        @: @Html.WarningMessageBox("Sorry Requested Auto Rickshaw test result cannot be edited.", "Access Denied!")
    }
    else
    {
        if (_HasSaved)
        {
            @Html.SuccessMessageBox("Congratulations! The Test Result saved successfully.")
        }
        else if (ViewData[AppConstants.ViewDataKeys.SAVED] != null && !_HasSaved)
        {
            @Html.WarningMessageBox("Sorry! we could not save the Test Result.")
        }
		@Html.HiddenFor(model => model.ID)       

        @*<div class="editor-label">Serial Number</div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.SerialNumber)
            @Html.ValidationMessageFor(model => model.SerialNumber)
        </div>
    
        <div class="editor-label">@Html.LabelFor(model => model.TestPerformedOn)</div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.TestPerformedOn, new { @class="datepicker" })
            @Html.ValidationMessageFor(model => model.TestPerformedOn)
        </div>*@        
    
        @Html.Partial("_EditZGL", Model)
        @*@Html.Partial("_ZGLDynamicUI", Model)*@
        
        @Html.HiddenFor(model => model.ZGLID)
        @Html.HiddenFor(model => model.TestStatus)
		@Html.HiddenFor(model => model.HasConfirmed)
        @Html.HiddenFor(model => model.HasPublished)
        @*@Html.HiddenFor(model => model.TestPerformedOn)*@
		@Html.HiddenFor(model => model.CreatedOn)
		@Html.HiddenFor(model => model.ModifiedOn)
		@Html.HiddenFor(model => model.ModifiedBy)
        @Html.HiddenFor(model => model.CreatedBy)
        @Html.HiddenFor(model => model.TestRound)
        @*@Html.HiddenFor(model => model.SerialNumber)*@
    
        @Html.HiddenFor(model => model.Vehicle.RegistrationNo)
        @Html.HiddenFor(model => model.Vehicle.RegistrationDate)
        @Html.HiddenFor(model => model.Vehicle.EngineNo)
        @Html.HiddenFor(model => model.Vehicle.ChasisNo)
        @Html.HiddenFor(model => model.Vehicle.OwnerName)
        @Html.HiddenFor(model => model.Vehicle.Address)
        @Html.HiddenFor(model => model.Vehicle.CellPhone)
        @Html.HiddenFor(model => model.Vehicle.CNGCylinderNo)
        @Html.HiddenFor(model => model.Vehicle.FormSubmissionDate)
        @Html.HiddenFor(model => model.Vehicle.BRTANumber)
		
        <div class="jb-button-container">
			<button class="btn btn-primary" type="submit" data-loading-text="Saving..."><i class="icon-hdd icon-white"></i> Save</button>
		</div>		
    }
}
</div>
<!--Modal Popup Section Start-->
<div id="divPhotoEditModal">
    <iframe id="iframeImageList" scrolling="no" frameborder="0" src=""></iframe>
</div>
<!--Modal Popup Section End-->

@*Following styles should be changed in Confirm.cshtml also for consistency, if changed anything*@
@section PageHeadSection
{
    <link href="@Url.Content("~/Content/themes/jb-ui/jquery.ui.all.css")" rel="stylesheet" type="text/css" />
    <style type="text/css">
        #divPhotoEditModal{width:980px; height:550px; padding:0px;}
        #iframeImageList{width:100%;}
        label{display:inline;}
        table.data-table-list th{font-weight:bolder; color:#000000; background-color:#ffffff; text-align:center;}
        .data-table-list td.right{text-align:right;}
        .data-table-list td.center{text-align:center;}
        input[type="text"]{width:50px; padding-top:1px; padding-bottom:1px; margin:0px;}
        input[type="text"].large{width:auto; padding-top:1px; padding-bottom:1px; margin:0px;}
        
        /*.data-table-list td:nth-child(2), .data-table-list td:nth-child(3){text-align:right;}*/
        div.spacer{margin:20px;}
    </style>
}
@section JavaScriptPlaceHolder
{
    @Html.JavaScript("jquery.validate.min.js", Url)
    @Html.JavaScript("jquery.validate.unobtrusive.min.js", Url)
    @Html.JavaScript("jquery-ui-1.8.11.min.js", Url)
    @Html.Partial("_DatePicker")

    <script language="javascript" type="text/javascript">
        var _PhotoDialog = null;
        $(document).ready(function () {
            _PhotoDialog = $('#divPhotoEditModal').dialog({
                autoOpen: false,
                title: 'Manage Auto Rickshaw Picture',
                modal: true,
                width: $('#divPhotoEditModal').width(),
                height: $('#divPhotoEditModal').height()
            });
        });
        function AdjustiFrameHeight(height) {
            //alert(height);
            $('#iframeImageList').height(height + 40);
        }
        function ChildHideLoading() {
            HideLoadingAnimation();
        }
        function SetLogo(pictureUrl) {
            var random = Math.floor((Math.random() * 100) + 1);
            $('#imgVehiclePicture').attr('src', pictureUrl + '?r=' + random);
            var parts = pictureUrl.split('/');
            $('#Vehicle_PictureFile').val(parts[parts.length - 1]);
            //alert('Set Logo: ' + parts[parts.length - 1]);
        }
        function ShowPhotoEditDialog() {
            $(_PhotoDialog).dialog('open');
            var iFrame = $(_PhotoDialog).find('iframe');
            if ($(iFrame).attr('src').length == 0) {
                $(iFrame).attr('src', '/Private/TestResult/PictureList/?VehicleID=@Model.Vehicle.ID');
                ShowLoadingAnimation(false);
            }
        } 
    </script>
}

